package cn.kgc.ywz.smbms.web.service.impl;

import cn.kgc.ywz.smbms.web.entity.Provider;
import cn.kgc.ywz.smbms.web.mapper.ProviderMapper;
import cn.kgc.ywz.smbms.web.service.ProviderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProviderServiceImpl implements ProviderService {

    @Resource
    private ProviderMapper providerMapper;

    /**
     * 查询
     */
    @Override
    public PageInfo<Provider> find(Provider condition, Integer pageNum, Integer pageSize) {
        if (pageNum == null) pageNum = 1;
        PageHelper.startPage(pageNum, pageSize);
        List<Provider> providerList = this.providerMapper.select(condition);
        PageInfo<Provider> pageInfo = new PageInfo<>(providerList);
        return pageInfo;
    }

    /**
     * 查询所有名称orId
     */
    @Override
    public List<Provider> findByProName() {
        return this.providerMapper.selectByProName();
    }

    /**
     * 添加供应商
     */
    @Override
    public int add(Provider provider) {
        return this.providerMapper.insert(provider);
    }

    /**
     * 修改供应商
     */
    @Override
    public int update(Provider provider) {
        return this.providerMapper.update(provider);
    }

    /**
     * 删除供应商
     */
    @Override
    public int remove(Long id) {
        return this.providerMapper.delete(id);
    }

    /**
     * 查询供应商编码
     */
    @Override
    public Integer findProCode(String proCode) {
        return this.providerMapper.selectProCode(proCode);
    }
}
